<!--
 * @Description: 
 * @Version: 2.0
 * @Autor: zhangjx
 * @Date: 2023-05-29 19:05:02
 * @LastEditors: zhangjx
 * @LastEditTime: 2023-06-09 11:27:01
-->
<template>
	<div>
		<AplidForm v-bind="formConfig('next')" v-model="formModel" @submit="onSubmit"> </AplidForm>
	</div>
</template>

<script setup lang="ts">
import apiMod from '@/apiMod/index'
import { formConfig } from '../menuHooks'
const emit = defineEmits(['refresh'])
const props = defineProps({
	nowMenu: Object,
	deviceType: [String, Number],
	id: [String, Number],
})

const formModel: any = ref({
	sort: 999,
	type: '0',
})
watch(
	() => props.id,
	() => {
		formModel.value = props.nowMenu || {}
	}
)

const onSubmit = (form, done) => {
	apiMod
		.sys_menu_add({
			...form,
			deviceType: props.deviceType,
			parentId: props.id,
		})
		.then((res) => {
			const query = {
				...res.data,
				id: res.data.menuId,
				label: res.data.name,
			}
			emit('refresh', query, 'add')
			done()
		})
}
</script>

<style scoped></style>
